package com.filetransfer.view.Components.render;
import com.filetransfer.utils.SystemUtils;
import lombok.extern.slf4j.Slf4j;
import raven.toast.Notifications;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
@Slf4j
public class LocalPathRender extends MessageViewButton implements TableCellRenderer {
    private Object value;
    public LocalPathRender() {
        super();
        //按钮点击事件
        super.getViewButton().addActionListener(
                e -> {
                    Notifications.getInstance().show(
                            Notifications.Type.SUCCESS,
                            Notifications.Location.BOTTOM_LEFT,
                            "正在打开文件资源管理器"
                    );
                    log.info("打开文件资源管理器: {}", value);
                    SystemUtils.showFileInFolder((String) value);
                }
        );
    }
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        this.value = value;
        log.info("value: {}", value);
        configureButton((String) value);
        if (isSelected) {
            setBackground(table.getSelectionBackground());
        } else {
            setBackground(table.getBackground());
        }
        return this;
    }
}
